package com.xuecheng.content.controller;

import com.xuecheng.base.exception.ValidatedGroups;
import com.xuecheng.content.model.dto.SaveOrUpdateCourseTeacherDTO;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.ICourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 勾新杰
 * @version 1.0
 * @description 课程教师信息管理控制器
 * @date 2025/1/9 13:58
 */
@RestController
@RequestMapping("/course-teacher")
@RequiredArgsConstructor
@Api(value = "课程教师管理接口", tags = "课程教师管理接口")
public class CourseTeacherController {

    private final ICourseTeacherService courseTeacherService;

    /**
     * 课程教师列表
     *
     * @param courseId 课程id
     * @return 该课程的教师列表
     */
    @GetMapping("/list/{courseId}")
    @ApiOperation("课程教师列表")
    public List<CourseTeacher> list(@PathVariable Long courseId) {
        return courseTeacherService.list(courseId);
    }

    /**
     * 添加课程教师
     *
     * @param saveOrUpdateCourseTeacherDTO 课程教师信息
     * @return 课程教师信息
     */
    @PostMapping
    @ApiOperation("添加或者更新课程教师")
    public CourseTeacher saveOrUpate(@RequestBody SaveOrUpdateCourseTeacherDTO saveOrUpdateCourseTeacherDTO) {
        if (saveOrUpdateCourseTeacherDTO.getId() == null)
            return courseTeacherService.save(saveOrUpdateCourseTeacherDTO);
        else
            return courseTeacherService.update(saveOrUpdateCourseTeacherDTO);
    }

    /**
     * 删除课程教师
     *
     * @param courseId 课程id
     * @param id       教师id
     */
    @DeleteMapping("/{courseId}/{id}")
    @ApiOperation("删除课程教师")
    public void delete(@PathVariable Long courseId, @PathVariable Long id) {
        courseTeacherService.remove(courseId, id);
    }
}
